package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/changdu/config"
	"gitee.com/leo-xin/novel_distribution_sdk_go/changdu/enums"
	"net/http"
	"net/url"
)

type GetBoundPackageListV1ApiService service

type GetBoundPackageListV1GetRequest struct {
	ctx           context.Context
	ApiService    *GetBoundPackageListV1ApiService
	distributorId *uint64
	appId         *uint64
	pageIndex     *uint64
	pageSize      *uint64
}

type GetBoundPackageListV1GetResponse struct {
	Code                *int64                   `json:"code,omitempty"`
	Message             *string                  `json:"message,omitempty"`
	PackageInfoOpenList []*WxPackageInfoOpenData `json:"wx_package_info_open_list,omitempty"`
	Total               *uint64                  `json:"total,omitempty"`
}

type WxPackageInfoOpenData struct {
	DistributorId *uint64        `json:"distributor_id,omitempty"`
	AppId         *uint32        `json:"app_id,omitempty"`
	AppName       *string        `json:"app_name,omitempty"`
	AppType       *enums.AppType `json:"app_type,omitempty"`
	WechatAppId   *string        `json:"wechat_app_id,omitempty"`
	Channel       *uint64        `json:"channel,omitempty"`
	Nickname      *string        `json:"nickname,omitempty"`
}

func (r *GetBoundPackageListV1GetRequest) DistributorId(distributorId uint64) *GetBoundPackageListV1GetRequest {
	r.distributorId = &distributorId
	return r
}

func (r *GetBoundPackageListV1GetRequest) AppId(appId uint64) *GetBoundPackageListV1GetRequest {
	r.appId = &appId
	return r
}

func (r *GetBoundPackageListV1GetRequest) PageIndex(page uint64) *GetBoundPackageListV1GetRequest {
	r.pageIndex = &page
	return r
}

func (r *GetBoundPackageListV1GetRequest) PageSize(pageSize uint64) *GetBoundPackageListV1GetRequest {
	r.pageSize = &pageSize
	return r
}

func (r *GetBoundPackageListV1GetRequest) Execute() (*GetBoundPackageListV1GetResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *GetBoundPackageListV1GetRequest) SecretKey(SecretKey string) *GetBoundPackageListV1GetRequest {
	r.ctx = context.WithValue(r.ctx, config.SecretKey, SecretKey)
	return r
}

func (r *GetBoundPackageListV1GetRequest) WithLog(enable bool) *GetBoundPackageListV1GetRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *GetBoundPackageListV1ApiService) Get(ctx context.Context) *GetBoundPackageListV1GetRequest {
	return &GetBoundPackageListV1GetRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *GetBoundPackageListV1ApiService) getExecute(r *GetBoundPackageListV1GetRequest) (*GetBoundPackageListV1GetResponse, *http.Response, error) {
	var (
		localVarPath         = a.client.Cfg.GetBasePath() + "/novelsale/openapi/wx/get_bound_package_list/v1/"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *GetBoundPackageListV1GetResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasReqParam(r.distributorId, "DistributorId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	if ok, GenericOpenAPIError := hasReqParam(r.appId, "AppId"); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}

	localVarQueryParams.Add("distributor_id", toString(r.distributorId))
	localVarQueryParams.Add("app_id", toString(r.appId))

	if r.pageIndex != nil {
		localVarQueryParams.Add("page_index", toString(r.pageIndex))
	}
	if r.pageSize != nil {
		localVarQueryParams.Add("page_size", toString(r.pageSize))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
